home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Gfx / Edit / TSMorph / src / Progress.c < prev    next >
C/C++ Source or Header  |  1994-10-30  |  7KB  |  268 lines

  1. // TSMorph - Amiga Morphing program
  2. // Copyright (C) © 1993  Topicsave Limited
  3.  
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // any later version.
  8.  
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13.  
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // mpaddock@cix.compulink.co.uk
  19.  
  20. /*
  21.  *  Source machine generated by GadToolsBox V2.0
  22.  *  which is (c) Copyright 1991-1993 Jaba Development
  23.  *
  24.  *  GUI Designed by : M J P
  25.  */
  26.  
  27. // Minor editing by MJP
  28.  
  29. #include <exec/types.h>
  30. #include <intuition/intuition.h>
  31. #include <intuition/classes.h>
  32. #include <intuition/classusr.h>
  33. #include <intuition/imageclass.h>
  34. #include <intuition/gadgetclass.h>
  35. #include <libraries/gadtools.h>
  36. #include <graphics/displayinfo.h>
  37. #include <graphics/gfxbase.h>
  38. #include <clib/exec_protos.h>
  39. #include <clib/intuition_protos.h>
  40. #include <clib/gadtools_protos.h>
  41. #include <clib/graphics_protos.h>
  42. #include <clib/utility_protos.h>
  43. #include <clib/alib_protos.h>
  44. #include <string.h>
  45. #include <pragmas/exec_pragmas.h>
  46. #include <pragmas/intuition_pragmas.h>
  47. #include <pragmas/gadtools_pragmas.h>
  48. #include <pragmas/graphics_pragmas.h>
  49. #include <pragmas/utility_pragmas.h>
  50.  
  51. extern struct Library *SysBase,*GfxBase;
  52. extern struct Library *UtilityBase;
  53.  
  54. #include "progress.h"
  55.  
  56. struct Screen         *Scr = NULL;
  57. UBYTE                 *PubScreenName = NULL;
  58. APTR                   VisualInfo = NULL;
  59. struct Window         *ProgressWnd = NULL;
  60. struct Gadget         *ProgressGList = NULL;
  61. struct IntuiMessage    ProgressMsg;
  62. UWORD                  ProgressZoom[4];
  63. struct Gadget         *ProgressGadgets[4];
  64. UWORD                  ProgressLeft = 215;
  65. UWORD                  ProgressTop = 42;
  66. UWORD                  ProgressWidth = 261;
  67. UWORD                  ProgressHeight = 133;
  68. UBYTE                 *ProgressWdt = (UBYTE *)"TSMorph Progress";
  69. struct TextAttr       *Font, Attr;
  70. UWORD                  FontX, FontY;
  71. UWORD                  OffX, OffY;
  72.  
  73. UWORD ProgressGTypes[] = {
  74.     SLIDER_KIND,
  75.     SLIDER_KIND,
  76.     BUTTON_KIND,
  77.     LISTVIEW_KIND
  78. };
  79.  
  80. struct NewGadget ProgressNGad[] = {
  81.     52, 78, 176, 11, (UBYTE *)"Frame", NULL, GD_Frame, PLACETEXT_LEFT, NULL, (APTR)FrameClicked,
  82.     52, 95, 176, 11, (UBYTE *)"Line", NULL, GD_Line, PLACETEXT_LEFT, NULL, (APTR)LineClicked,
  83.     82, 111, 95, 19, (UBYTE *)"Stop", NULL, GD_Stop, PLACETEXT_IN, NULL, (APTR)StopClicked,
  84.     6, 6, 251, 65, NULL, NULL, GD_Info, 0, NULL, NULL
  85. };
  86.  
  87. extern struct List InfoList;
  88.  
  89. ULONG ProgressGTags[] = {
  90.     (GTSL_Max), 999, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, GA_Disabled,TRUE,(TAG_DONE),
  91.     (GTSL_Max), 999, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, GA_Disabled,TRUE,(TAG_DONE),
  92.     (TAG_DONE),
  93.     (GTLV_Labels), (ULONG)&InfoList, (GTLV_ReadOnly), TRUE, (TAG_DONE)
  94. };
  95.  
  96. static UWORD ComputeX( UWORD value )
  97. {
  98.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  99. }
  100.  
  101. static UWORD ComputeY( UWORD value )
  102. {
  103.     return(( UWORD )((( FontY * value ) + 5 ) / 10 ));
  104. }
  105.  
  106. static void ComputeFont( UWORD width, UWORD height )
  107. {
  108.     Font = &Attr;
  109.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  110.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  111.     FontX = Scr->RastPort.Font->tf_XSize;
  112.  
  113.     OffX = Scr->WBorLeft;
  114.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  115.  
  116.     if ( width && height ) {
  117.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  118.             goto UseTopaz;
  119.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  120.             goto UseTopaz;
  121.     }
  122.     return;
  123.  
  124. UseTopaz:
  125.     Font->ta_Name = (STRPTR)"topaz.font";
  126.     FontX = FontY = Font->ta_YSize = 8;
  127. }
  128.  
  129. int SetupScreen( void )
  130. {
  131.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  132.         return( 1L );
  133.  
  134.     ComputeFont( 0, 0 );
  135.  
  136.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  137.         return( 2L );
  138.  
  139.     return( 0L );
  140. }
  141.  
  142. void CloseDownScreen( void )
  143. {
  144.     if ( VisualInfo ) {
  145.         FreeVisualInfo( VisualInfo );
  146.         VisualInfo = NULL;
  147.     }
  148.  
  149.     if ( Scr        ) {
  150.         UnlockPubScreen( NULL, Scr );
  151.         Scr = NULL;
  152.     }
  153. }
  154. typedef int (FPTR(void));
  155. int HandleProgressIDCMP( void )
  156. {
  157.     struct IntuiMessage    *m;
  158.     int            (*func)(void);
  159.     BOOL            running = TRUE;
  160.  
  161.     while( m = GT_GetIMsg( ProgressWnd->UserPort )) {
  162.  
  163.         CopyMem(( char * )m, ( char * )&ProgressMsg, (long)sizeof( struct IntuiMessage ));
  164.  
  165.         GT_ReplyIMsg( m );
  166.  
  167.         switch ( ProgressMsg.Class ) {
  168.  
  169.             case    IDCMP_REFRESHWINDOW:
  170.                 GT_BeginRefresh( ProgressWnd );
  171.                 GT_EndRefresh( ProgressWnd, TRUE );
  172.                 break;
  173.  
  174.             case    IDCMP_RAWKEY:
  175.                 running = ProgressRawKey();
  176.                 break;
  177.  
  178.             case    IDCMP_GADGETUP:
  179. //            case    IDCMP_GADGETDOWN:
  180.                 func = (FPTR *)(( struct Gadget * )ProgressMsg.IAddress )->UserData;
  181.                 running = func();
  182.                 break;
  183.         }
  184.     }
  185.     return( (int) running );
  186. }
  187.  
  188. int OpenProgressWindow( void )
  189. {
  190.     struct NewGadget    ng;
  191.     struct Gadget    *g;
  192.     UWORD        lc, tc;
  193.     UWORD        wleft = ProgressLeft, wtop = ProgressTop, ww, wh;
  194.  
  195.     NewList(&InfoList);
  196.  
  197.     ComputeFont( ProgressWidth, ProgressHeight );
  198.  
  199.     ww = ComputeX( ProgressWidth );
  200.     wh = ComputeY( ProgressHeight );
  201.  
  202.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  203.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  204.  
  205.     if ( ! ( g = CreateContext( &ProgressGList )))
  206.         return( 1L );
  207.  
  208.     for( lc = 0, tc = 0; lc < Progress_CNT; lc++ ) {
  209.  
  210.         CopyMem((char * )&ProgressNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  211.  
  212.         ng.ng_VisualInfo = VisualInfo;
  213.         ng.ng_TextAttr   = Font;
  214.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  215.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  216.         ng.ng_Width      = ComputeX( ng.ng_Width );
  217.         ng.ng_Height     = ComputeY( ng.ng_Height);
  218.  
  219.         ProgressGadgets[ lc ] = g = CreateGadgetA((ULONG)ProgressGTypes[ lc ], g, &ng, ( struct TagItem * )&ProgressGTags[ tc ] );
  220.  
  221.         while( ProgressGTags[ tc ] ) tc += 2;
  222.         tc++;
  223.  
  224.         if ( NOT g )
  225.             return( 2L );
  226.     }
  227.  
  228.         ProgressZoom[0] = ProgressZoom[1] = 0;
  229.     if ( ProgressWdt )
  230.         ProgressZoom[2] = TextLength( &Scr->RastPort, (UBYTE *)ProgressWdt, strlen((char *)ProgressWdt )) + 80;
  231.     else
  232.         ProgressZoom[2]  = 80L;
  233.         ProgressZoom[3] = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  234.  
  235.     if ( ! ( ProgressWnd = OpenWindowTags( NULL,
  236.                 WA_Left,    wleft,
  237.                 WA_Top,        wtop,
  238.                 WA_Width,    ww + OffX + Scr->WBorRight,
  239.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  240.                 WA_IDCMP,    BUTTONIDCMP|LISTVIEWIDCMP|IDCMP_RAWKEY|IDCMP_REFRESHWINDOW,
  241.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH,
  242.                 WA_Gadgets,    ProgressGList,
  243.                 WA_Title,    ProgressWdt,
  244.                 WA_ScreenTitle,    "TSMorph ©1993/94 Topicsave Limited",
  245.                 WA_PubScreen,    Scr,
  246.                 WA_Zoom,    ProgressZoom,
  247.                 TAG_DONE )))
  248.     return( 4L );
  249.  
  250.     GT_RefreshWindow( ProgressWnd, NULL );
  251.  
  252.     return( 0L );
  253. }
  254.  
  255. void CloseProgressWindow( void )
  256. {
  257.     if ( ProgressWnd        ) {
  258.         CloseWindow( ProgressWnd );
  259.         ProgressWnd = NULL;
  260.     }
  261.  
  262.     if ( ProgressGList      ) {
  263.         FreeGadgets( ProgressGList );
  264.         ProgressGList = NULL;
  265.     }
  266. }
  267.  
  268.